package com.edu.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.edu.entity.CommonResult;
import com.edu.entity.Conditions;
import com.edu.entity.Goods;
import com.edu.entity.GoodsToWeb;
import com.edu.entity.Orders;
import com.edu.entity.OrdersDTO;
import com.edu.entity.Page;
import com.edu.service.GoodService;
import com.edu.service.OrdersService;
import com.edu.service.impl.GoodServiceImpl;
import com.edu.service.impl.OrdersServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;

@WebServlet("/updateOrder")
public class updateOrderServlet extends HttpServlet {
	OrdersService os = new OrdersServiceImpl();
	CommonResult cr = new CommonResult();
	GoodService gs = new GoodServiceImpl();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		ObjectMapper om = new ObjectMapper();
		Conditions con = new Conditions();
		Goods goods = new Goods();
		ArrayList<GoodsToWeb> listGoods = new ArrayList<GoodsToWeb>();
		ArrayList listgood = new ArrayList();
		String orderIdString = request.getParameter("orderId");
		String stateString = request.getParameter("state");
		int orderId;
		int state;
		try {
			orderId = Integer.parseInt(orderIdString);
			state = Integer.parseInt(stateString);
			int result = os.setOrder(orderId,state);
			if(result==1) {
				cr.setCode(200);
				cr.setMessage("success");
			}else {
				cr.setCode(409);
				cr.setMessage("fail");
			}
		} catch (Exception e) {
			cr.setCode(409);
			cr.setMessage("fail");
		}
		response.setContentType("application/json;charset=utf-8");
		response.getWriter().write(cr.toJsonString());
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}
}
